package assembler

import (
	"github.com/jinzhu/copier"
	"gotham-plan-manage/internal/domain/command"
	"gotham-plan-manage/internal/domain/query"
	"gotham-plan-manage/proto/gotham-plan-manage-proto/plan"
	"gotham-plan-manage/proto/gotham-plan-manage-proto/task"
)

/*
计划管理-DTO和命令转换器
*/

type PlanManageAssembler struct {
}

// ToCommandFromCreateRequest 创建计划Request转命令
func (p *PlanManageAssembler) ToCommandFromCreateRequest(req *plan.CreateRequest) *command.PlanCreateCommand {
	return &command.PlanCreateCommand{
		Name:      req.Name,
		StartDate: req.StartDate,
		EndDate:   req.EndDate,
		ParentId:  req.ParentId,
	}
}

// ToCommandFromDeleteRequest 删除计划Request转命令
func (p *PlanManageAssembler) ToCommandFromDeleteRequest(req *plan.DeleteRequest) *command.PlanDeleteCommand {
	return &command.PlanDeleteCommand{
		PlanId: req.Id,
	}
}

// ToCommandFromEditRequest 编辑计划Request转命令
func (p *PlanManageAssembler) ToCommandFromEditRequest(req *plan.EditRequest) *command.PlanEditCommand {
	return &command.PlanEditCommand{
		PlanId:    req.PlanId,
		Name:      req.Name,
		StartDate: req.StartDate,
		EndDate:   req.EndDate,
		ParentId:  req.ParentId,
	}
}

// ToQueryFromGenerateReportRequest 生成计划报告Request转查询
func (p *PlanManageAssembler) ToQueryFromGenerateReportRequest(req *plan.PlanIdRequest) *query.GeneratePlanReportQuery {
	return &query.GeneratePlanReportQuery{PlanId: req.PlanId}
}

func (p *PlanManageAssembler) ToCommandFromEditTargetRequest(req *plan.EditTargetRequest) *command.TargetEditCommand {
	return &command.TargetEditCommand{
		PlanID: req.PlanId,
		Target: req.Target,
	}
}

func (p *PlanManageAssembler) ToQueryFromGetPlanDetailRequest(req *plan.PlanIdRequest) *query.GetPlanDetailQuery {
	return &query.GetPlanDetailQuery{PlanId: req.PlanId}
}

func (p *PlanManageAssembler) ToQueryFromGetPlanRequest(req *plan.PlanIdRequest) *query.GetPlanQuery {
	return &query.GetPlanQuery{PlanId: req.PlanId}
}

func (p *PlanManageAssembler) ToQueryFromGetPlanList(req *plan.GetPageRequest) *query.GetPlanListQuery {
	return &query.GetPlanListQuery{
		Page:     int(req.Page),
		PageSize: int(req.PageSize),
	}
}

func (p *PlanManageAssembler) ToCommandFromSubmitPlanReport(req *plan.SubmitReportRequest) *command.PlanReportSubmitCommand {
	res := &command.PlanReportSubmitCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromFindPlanReport(req *plan.PlanIdRequest) *query.FindPlanReportQuery {
	res := &query.FindPlanReportQuery{PlanId: req.PlanId}
	return res
}

func (p *PlanManageAssembler) ToCommandFromCreateTaskItemRequest(req *task.CreateItemRequest) *command.CreateTaskCommand {
	res := &command.CreateTaskCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToCommandFromDeleteTaskItemById(req *task.IdRequest) *command.DeleteTaskItemCommand {
	return &command.DeleteTaskItemCommand{
		TaskItemId: req.Id,
	}
}

func (p *PlanManageAssembler) ToCommandFromDeleteTaskById(req *task.IdRequest) *command.DeleteTaskCommand {
	return &command.DeleteTaskCommand{TaskId: req.Id}
}

func (p *PlanManageAssembler) ToQueryFromGetTaskItemById(req *task.IdRequest) *query.GetTaskItemQuery {
	return &query.GetTaskItemQuery{TaskItemId: req.Id}
}

func (p *PlanManageAssembler) ToQueryFromGetTaskList(req *task.GetTaskListRequest) *query.GetTaskListQuery {
	res := &query.GetTaskListQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToCommandFromEditTaskItem(req *task.EditItemRequest) *command.EditTaskItemCommand {
	res := &command.EditTaskItemCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToCommandFromFinishTaskItem(req *task.IdRequest) *command.FinishTaskItemCommand {
	return &command.FinishTaskItemCommand{TaskItemId: req.Id}
}

func (p *PlanManageAssembler) ToCommandFromSaveQuestionRequest(req *task.SaveQuestionRequest) *command.SaveQuestionCommand {
	res := &command.SaveQuestionCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromFindOneDayQuestions(req *task.FindOneDayQuestionsRequest) *query.FindOneDayQuestionQuery {
	res := &query.FindOneDayQuestionQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromSearchQuestionRequest(req *task.SearchQuestionsRequest) *query.SearchQuestionQuery {
	res := &query.SearchQuestionQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromGetOngoingTasksRequest(req *task.GetOngoingTaskItemsRequest) *query.GetOngoingTasksQuery {
	res := &query.GetOngoingTasksQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromIsFinishTaskRequest(req *task.IsFinishAllTaskRequest) *query.IsFinishTaskQuery {
	res := &query.IsFinishTaskQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromCompletionRateAnalysisRequest(req *plan.PlanIdRequest) *query.CompletionRateAnalysisQuery {
	return &query.CompletionRateAnalysisQuery{PlanID: req.PlanId}
}

func (p *PlanManageAssembler) ToQueryFromWeeklyDistributionAnalysisRequest(req *plan.PlanIdRequest) *query.WeeklyDistributionAnalysisQuery {
	return &query.WeeklyDistributionAnalysisQuery{PlanID: req.PlanId}
}

func (p *PlanManageAssembler) ToQueryFromReviewAnalysisRequest(req *plan.ReviewAnalysisRequest) *query.ReviewAnalysisQuery {
	return &query.ReviewAnalysisQuery{PlanID: req.PlanId}
}

func (p *PlanManageAssembler) ToCommandFromSetExpectTaskTotalRequest(req *plan.SetExpectTaskTotalRequest) *command.SetExpectTaskTotalCommand {
	return &command.SetExpectTaskTotalCommand{
		PlanId:                    req.PlanId,
		NextWeekTargetFinishTotal: req.NextWeekTargetFinishTotal,
	}
}
